<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="author" content="Guillaume Laborde - Guillaume Lameyre" />
<link rel="stylesheet" media="screen" type="text/css" title="style" href="css/style.css" />
<title>ContactBook</title>
</head>

<body>

	<c:set var="account" value="${sessionScope.account}" />
	<c:set var="message" value="${requestScope.message}" />
	<c:set var="contactFirstName" value="${requestScope.firstName}" />
	<c:set var="contactLastName" value="${requestScope.lastName}" />
	
	<c:if test="${empty account}">
		<c:redirect url="Index" />
	</c:if>
		
	<div id="mainframe">
		<c:import url="include/privateBanner.html" />
		<h1>Ajouter un Contact</h1>
		<div id="content">
		
			<c:choose>
				<c:when test="${message == 'CONTACT_CREATED_OK'}">
					<form action="Contact" method="POST" class="form">
					<table>
						<tr><td>Le nouveau contact a été créé avec succès !</td></tr>
						<tr><td class="button"><input type="image" src="images/back.png" alt="Retour" /></td></tr>
					</table>
				</form>
				</c:when>
				<c:when test="${message == 'CONTACT_CREATED_FAIL'}">
					<p class="error">La création du contact a échouée.</p>
				</c:when>
				<c:when test="${message == 'CONTACT_CREATED_LASTNAME_FAIL'}">
					<p class="error">Le nom de famille du contact doit être renseigné.</p>
				</c:when>	
			</c:choose>
		
			<c:if test="${message != 'CONTACT_CREATED_OK'}">
				<form action="AddContact" method="POST" class="form">
					<table>
						<tr>
							<td>Prénom</td>
							<td><input type="text" name="firstname" id="firstname" /></td>
						</tr>
						<tr>
							<td>Nom</td>
							<td><input type="text" name="lastname" id="lastname" /></td>
						</tr>
						<tr>
							<td>Groupe</td>
							<td>
								<select name="group" id="group" />
									<option value="0" selected="selected">Défaut</option>
									<c:forEach var="group" items="${requestScope.groups}">
										<jsp:useBean id="group" class="contactbook.model.Group" scope="page" />	
										<option value="<jsp:getProperty name="group" property="id" />"><jsp:getProperty name="group" property="name" /></option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td>Email</td>
							<td><input type="text" name="email" id="email" /></td>
						</tr>
						<tr>
							<td>Téléphone</td>
							<td><input type="text" name="phoneNumber" id="phoneNumber" /></td>
						</tr>
						<tr>
							<td>Adresse</td>
							<td><textarea name="address" id="address" cols="20" rows="4"></textarea></td>
						</tr>
						<tr>
							<td>Code postal</td>
							<td><input type="text" name="zipCode" id="zipCode" /></td>
						</tr>
						<tr>
							<td>Ville</td>
							<td><input type="text" name="town" id="town\" /></td>
						</tr>
						<tr>
							<td>Pays</td>
							<td><input type="text" name="country" id="country" /></td>
						</tr>
						<tr>
							<td>Situation familiale</td>
							<td>
								<select name="maritalStatus" id="maritalStatus" />
									<c:forEach var="maritalStatus" items="${requestScope.maritalStatus}">
											<option value="${maritalStatus}"><c:out value="${maritalStatus}" /></option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td>Age</td>
							<td><input type="text" name="age" id="age" /></td>
						</tr>
						<tr>
							<td colspan="2" class="button"><input type="submit" name="submit" value="Ajouter" /> <input type="submit" name="submit" value="Annuler" /></td>
						</tr>
					</table>
				</form>
			</c:if>
		</div>
		<c:import url="include/bottom.html" />
	</div>

</body>
</html>